package main

import (
	"fmt"
	"log"

	"gitee.com/korbenzhang/gox/xconfig"
	"gitee.com/korbenzhang/gox/xconfig/viperconf"
)

// demo config
var conf xconfig.Config

type User struct{
  Name string
  Age int
  Assets int
}

func main() {
  conf = viperconf.New()
  if err:=xconfig.MergeFile(conf, "demo.yaml");err!=nil{
    log.Print(err)
  }

  // simple get Demo
  v:=conf.GetString("Demo")
  if v!="Demo"{
    log.Print("expect Demo, got:",v)
  }

  // assets
  n:=xconfig.GetInt(conf, "User.Assets")
  fmt.Printf("assets: %d\n", n)

  // try env
  home:=conf.GetString("Env.Home")
  fmt.Printf("env home: %v\n", home )


  // marshal
  var user User
  conf.Unmarshal("User", &user)
  fmt.Printf("%v\n", user)
}
